class_name Enemy
extends CharacterBody2D

enum Direction {
	LEFT = -1,
	right = +1,
}

@export var direction := Direction.LEFT:
	set(value):
		direction = value
		if not is_node_ready():
			await ready
		graphics.scale.x = - direction
@export var max_speed:float = 180
@export var acceleration:float = 2000

# 从项目设置中获取重力值
var default_gravity := ProjectSettings.get("physics/2d/default_gravity") as float

@onready var graphics: Node2D = $graphics
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var state_machine: StateMachine = $StateMachine
@onready var stats: Stats = $Stats

func move (speed:float ,delta:float)->void:
	velocity.x = move_toward(velocity.x, speed*direction, acceleration * delta)	#应用加速度到水平速度
	velocity.y += default_gravity * delta			#应用重力
	move_and_slide()								#应用移动

func die()->void:
	queue_free() 
